class Solution {
    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> p=new PriorityQueue<Integer>((a,b)->b-a);
        for(int stone:stones){
            p.offer(stone);
        }
        while(p.size()>1){
            int a=p.poll();
            int b=p.poll();
            if(a>b){
                p.offer(a-b);
            }

        }
        return p.isEmpty()?0:p.poll();

    }
}
